﻿
// 2018/6/20: 首个记录
// 2018/8/10: LabelClass增加302~304，GeneralPed改为GeneralMinority
// 2018/8/14: 增加getTitle，支持significantCount
// 2018/8/15: 修正拼写错误
// 2018/10/16: 12路视频
// 2019/3/29: 添加注释
// 2019/10/11: 修改pragma once和include
// 2019/12/25: 添加若干标签种类
// 2020/1/14: 接口完整性
// 2020/11/12: 支持Spadas7
// 2021/4/6: 修正注释
// 2022/11/2: 支持Spadas8.4
// 2023/10/11: 补充部分英文注释
// 2023/11/1: 修正distance定义

#ifndef IMAGE_LABEL_SAMPLE_V1_H
#define IMAGE_LABEL_SAMPLE_V1_H

#include "spadas.h"

namespace image_label_sample_v1
{
	using namespace spadas;

	enum LabelClass
	{
		LBC_Unknown = 0, // 未知

		LBC_GeneralCar = 100, // General automobile / 机动车大类
		LBC_Car = 101, // 轿车
		LBC_Bus = 102,// 大巴
		LBC_Midibus = 103,// 小巴
		LBC_Truck = 104, // 货车
		LBC_Van = 105, // 面包车
		LBC_Semitrailer = 106, // 货柜车
		LBC_Trailer = 107, // 拖车
		LBC_SUV = 108, // SUV
		LBC_TinyCar = 109, // 微型车

		LBC_GeneralMinority = 200, // General vulnerable road user / 弱势参与者大类
		LBC_Pedestrian = 201, // Pedestrian / 行人
		LBC_Bicycle = 202, // 自行车
		LBC_Tricycle = 203, // 三轮车
		LBC_Motorbike = 204, // 摩托车
		LBC_Wheelchair = 205, // 轮椅
		LBC_Animal = 206, // 动物

		LBC_GeneralStatic = 300, // General static object / 静态目标大类
		LBC_ZebraCrossing = 301, // 斑马线
		LBC_TrafficLight = 302, // 交通灯
		LBC_TrafficSign = 303, // 交通信号
		LBC_ParkingSlot = 304, // 车位
		LBC_Cone = 305, // 锥形路障
		LBC_ManholeCover = 306, // 井盖
		LBC_Patch = 307, // 路面补丁
		LBC_Gantry = 308, // 龙门架
		LBC_Pole = 309, // 竖杆
		LBC_Tree = 310, // 树木
		LBC_Vegetation = 311, // 灌木
		LBC_Building = 312, // 建筑物
	};

	struct ImageLabel
	{
		LabelClass clas; // 标签类型
		UInt id; // 标签ID
		Float distance; // [m] Average distance between the label's pixels to the camera (along x axis of camera coordinate system) / 标签距摄像头的平均距离（沿摄像头x轴方向）
		Point2D topLeft; // [pix] Coordination of the top left point of label's border / 标签矩形框的左上角坐标
		Point2D bottomRight; // [pix] Coordination of the bottom right point of label's border / 标签矩形框的右下角坐标
	};

	struct ImageLabelSample
	{
		FullTimestamp timestamp; // 时间戳
		UInt channel; // Corresponding video channel / 对应的视频通道
		Size2D imageSize; // [pix] 图像尺寸
		Array<ImageLabel> labels; // List of labels / 标签列表

		ImageLabelSample()
		{
			channel = UINF;
		}

		static String getProtocolName(UInt channel)
		{
			if (channel == UINF) return "image-label-sample-v1";
			else return (String)"image-label-sample-v1@" + channel;
		}

		static Bool supportInterpolation()
		{
			return FALSE;
		}

		SessionGeneralSample toGeneralSample()
		{
			SessionGeneralSample sample;

			sample.timestamp = timestamp;
			sample.values = Array<GeneralElement>(4 + labels.size() * 7);
			GeneralElement *data = sample.values.data();

			data[0] = (Double)channel;
			data[1] = imageSize.width;
			data[2] = imageSize.height;
			data[3] = (Double)labels.size();
			for (UInt i = 0; i < labels.size(); i++)
			{
				ImageLabel& src = labels[i];
				data[7 * i + 4] = (Double)(UInt)src.clas;
				data[7 * i + 5] = (Double)src.id;
				data[7 * i + 6] = src.distance;
				data[7 * i + 7] = src.topLeft.u;
				data[7 * i + 8] = src.topLeft.v;
				data[7 * i + 9] = src.bottomRight.u;
				data[7 * i + 10] = src.bottomRight.v;
			}

			sample.significantCount = 4 + labels.size() * 7;
			return sample;
		}

		Bool fromGeneralSample(String protocol, SessionGeneralSample sample)
		{
			// TODO
			return FALSE;
		}

		static ImageLabelSample interpolate(ImageLabelSample& s1, Double w1, ImageLabelSample& s2, Double w2, FullTimestamp timestamp)
		{
			return ImageLabelSample();
		}
	};
}

#endif